package de.slothsoft.wasbinich.swingclient.common;

import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.logging.Logger;

import javax.swing.JLabel;

public final class SwingUtil {

    public static JLabel createLink(String name, final String url) {
	JLabel result = new JLabel("<html><a href=\"" + url + "\">" + name + "</a></html>");
	result.setCursor(new Cursor(Cursor.HAND_CURSOR));
	result.addMouseListener(new MouseAdapter() {
	    @Override
	    public void mouseClicked(MouseEvent e) {
		try {
		    Desktop.getDesktop().browse(new URI(url));
		} catch (URISyntaxException | IOException ex) {
		    Logger.getGlobal().severe(ex.getMessage());
		}
	    }
	});
	return result;
    }

    private SwingUtil() {
	// hide me
    }
}
